package com.zjj.day0425.object;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date 2025/4/25
 */
import java.util.ArrayList;
import java.util.List;

class Student {
    private String name;
    private String studentId;

    public Student(String name, String studentId) {
        this.name = name;
        this.studentId = studentId;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public String getStudentId() {
        return studentId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Student student = (Student) o;
        return name.equals(student.name) && studentId.equals(student.studentId);
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + studentId.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Student{name='" + name + "', studentId='" + studentId + "'}";
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 设置
     * @param studentId
     */
    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }
}

class StudentSystem {
    private List<Student> students;

    public StudentSystem() {
        this.students = new ArrayList<>();
    }

    public boolean addStudent(Student student) {
        if (students.contains(student)) {
            System.out.println("同名且同学号的学生已存在，不允许重复添加。");
            return false;
        }
        students.add(student);
        System.out.println("学生添加成功：" + student);
        return true;
    }

    public List<Student> getStudents() {
        return students;
    }
}

public class ObjectWork {
    public static void main(String[] args) {
        StudentSystem studentSystem = new StudentSystem();

        Student student1 = new Student("张三", "001");
        Student student2 = new Student("李四", "002");
        Student student3 = new Student("张三", "001");

        studentSystem.addStudent(student1);
        studentSystem.addStudent(student2);
        studentSystem.addStudent(student3);

        System.out.println("系统中的学生信息：");
        for (Student student : studentSystem.getStudents()) {
            System.out.println(student);
        }
    }
}